package stock;

public class Solution2 {

    public static void main(String[] args) {
        Solution1 solution2 = new Solution1();
        int[] prices = {7,1,5,3,6,4};
        int res =solution2.maxProfit(prices);
        System.out.println(res);
    }

    //如果后一条数据大于前一条数据，就计算其差，所有差的累计就是结果
    public int maxProfit(int[] prices){
        int result = 0;
        for (int i = 0; i < prices.length; i++) {
           if(i<prices.length-1){
               if(prices[i+1]>prices[i]){
                   result = result+ (prices[i+1]-prices[i]);
               }
           }
        }
        return result;
    }
}
